package com.shanks.home.module.media;

import java.util.HashMap;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

import com.shanks.home.R;

/**
 * @author Shanks
 * @time 2013.11.18
 */
public class ShanksSoundPool {
	
	private static ShanksSoundPool instance;
	private Context context;
	private SoundPool soundPool;
	private HashMap<Integer, Integer> soundMap = new HashMap<Integer, Integer>();
	
	public static ShanksSoundPool getInstance(Context c) {
		if (instance == null) {
			instance = new ShanksSoundPool(c);
		}
		return instance;
	}
	
	public ShanksSoundPool(Context c) {
		context = c;
		
		init();
	}
	
	private void init() {
		// load需要一定的时间，只有load完成了才能播放对应声音
		soundPool = new SoundPool(10, AudioManager.STREAM_SYSTEM, 5);
		soundMap.put(1, soundPool.load(context, R.raw.dog, 1));
		soundMap.put(2, soundPool.load(context, R.raw.kiss, 1));
	}
	
	public void play() {
		soundPool.play(soundMap.get(1), 1, 1, 0, 0, 1);
	}
}